home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 14 / compu-calc! / calc.asm < prev    next >
Encoding:
Assembly Source File  |  1994-01-27  |  10.7 KB  |  648 lines

  1.     nolist
  2.     include 'exec/types.i'
  3.     include 'exec/memory.i'
  4.     include 'intuition/intuition.i'
  5. ;    include 'intuition.i'
  6.     list
  7.  
  8. ;    Calc.asm
  9. ;    Version 1.0.001
  10. ;
  11. ;    These routines take care of handling all intuition input
  12. ;    and all window activies. It also handles the allocating
  13. ;    and deallocating of gadgets in chip memory.
  14. ;
  15.  
  16. execute    MACRO
  17.     XREF    _LVO\1
  18.     jsr    _LVO\1(a6)
  19.     ENDM
  20.  
  21.     xref    Gadg,HEX,Decimal,Octal,hp,ocp,dp
  22.     xref    BIN,_CLR,Bp,Cp
  23.     xref    Zero,One,Two,Three,zp,op,twop,thrp
  24.     xref    Four,Five,Six,Seven,fp,fip,sip,sep
  25.     xref    Eight,Nine,Ten,Eleven,ep,np,tp,elp
  26.     xref    Twelve,Thrten,Forten,Fiften,twp,thp,fop,fifp
  27.     xref    Plus,Minus,Multi,Divide,Plp,Mip,Mup,Dip
  28.     xref    Equal,_Title,Eqp,Tip
  29.     xref    GadT,num,Clear,Cl,Funct,Itext0,Iok,ReqNam
  30.     xref    Igt,ReqNam1,HItext0
  31.     xref    Display,VarPtr
  32.     xdef    Finevnt,Input
  33.  
  34. *    A0 contains a pointer to the CLI input command.
  35. *    D0 contains the length of that string.
  36.  
  37. ExecB    Equ    4
  38.  
  39. *    Window.asm
  40.  
  41. start    move.l    ExecB,a6
  42.     move.w    #0,d0        ; Hex Default Input Method
  43.     lea    Input,a0
  44.     move.w    d0,0(a0)
  45.  
  46.     lea    Table,a4    ; Memory allocation routine
  47.     moveq    #0,d1
  48. aloc    move.l    0(a4,d1),d0
  49.     tst.l    d0
  50.     beq.s    cont
  51.     move.l    4(a4,d1),a2
  52.     jsr    Amem(pc)
  53.     tst.l    d0
  54.     beq.l     A_Err
  55.     move.l    d0,8(a4,d1)
  56.     move.l    12(a4,d1),a1
  57.     move.l    d0,(a1)
  58.     addi.l    #16,d1
  59.     jmp    aloc(pc)
  60.  
  61.  
  62. cont    lea    intuit,a1
  63.     moveq    #0,d0
  64.     execute    OpenLibrary
  65.     tst.l    d0
  66.     beq.l    e_int
  67.  
  68.     lea    Libstg,a3
  69.     move.l    d0,0(a3)
  70.  
  71.     lea    graph,a1
  72.     moveq    #0,d0
  73.     execute    OpenLibrary
  74.     tst.l    d0
  75.     beq.l    e_int
  76.  
  77.     lea    Libstg,a3
  78.     move.l    d0,4(a3)
  79.  
  80.     move.l    0(a3),a6
  81.     lea    MyWin,a0
  82.     execute    OpenWindow
  83.     move.l    d0,a4            ;Window Pointer in A4
  84.  
  85.     lea    Libstg,a3
  86.     move.l    4(a3),a6
  87.  
  88.     move.l    wd_RPort(a4),a1
  89.     moveq    #1,d0
  90.     execute    SetAPen
  91.  
  92.     move.l    wd_RPort(a4),a1
  93.     moveq    #15,d0
  94.     moveq    #14,d1
  95.     execute    Move
  96.  
  97.     move.l    wd_RPort(a4),a1
  98.     move.l    #276,d0
  99.     moveq    #14,d1
  100.     execute    Draw
  101.  
  102.     move.l    wd_RPort(a4),a1
  103.     move.l    #276,d0
  104.     move.l    #54,d1
  105.     execute    Draw
  106.  
  107.     move.l    wd_RPort(a4),a1
  108.     move.l    #15,d0
  109.     move.l    #54,d1
  110.     execute    Draw
  111.  
  112.     move.l    wd_RPort(a4),a1
  113.     move.l    #15,d0
  114.     move.l    #14,d1
  115.     execute    Draw
  116.  
  117.     move.l    wd_RPort(a4),a1
  118.     move.l    #15,d0
  119.     move.l    #24,d1
  120.     execute    Draw
  121.  
  122.     move.l    wd_RPort(a4),a1
  123.     move.l    #276,d0
  124.     move.l    #24,d1
  125.     execute    Draw
  126.  
  127.     move.l    wd_RPort(a4),a1
  128.     move.l    #276,d0
  129.     move.l    #34,d1
  130.     execute    Draw
  131.  
  132.     move.l    wd_RPort(a4),a1
  133.     move.l    #15,d0
  134.     move.l    #34,d1
  135.     execute    Draw
  136.  
  137.     move.l    wd_RPort(a4),a1
  138.     move.l    #15,d0
  139.     move.l    #44,d1
  140.     execute    Draw
  141.  
  142.     move.l    wd_RPort(a4),a1
  143.     move.l    #276,d0
  144.     move.l    #44,d1
  145.     execute    Draw
  146.  
  147. ;    Main
  148.  
  149.     lea    Libstg,a3
  150.     move.l    0(a3),a6
  151.     jsr    Cl
  152.     move.l    ExecB,a6
  153. gmsg    move.l    wd_UserPort(a4),a0
  154.     execute    WaitPort
  155. clfifo    move.l    wd_UserPort(a4),a0
  156.     execute    GetMsg
  157.     tst.l    d0
  158.     beq.s    gmsg
  159.     move.l    d0,d6
  160.     move.l    d0,a1
  161.     move.l    wd_UserPort(a4),a0
  162.     execute    ReplyMsg
  163.     move.l    d6,a0
  164.     move.l    im_Class(a0),d0
  165.     cmpi.l    #CLOSEWINDOW,d0
  166.     beq.l    close
  167.     cmpi.l    #RAWKEY,d0
  168.     beq.l    Key
  169.     move.l    im_IAddress(a0),a0
  170.     moveq    #0,d0
  171.     move.w    gg_GadgetID(a0),d0
  172.     move.l    d0,d1
  173.     cmpi.l    #26,d0
  174.     bgt.s    Finevnt
  175.     lea    jptbl,a1
  176.     mulu    #4,d0
  177.     move.l    0(a1,d0.w),a0
  178.     lea    Libstg,a3
  179.     move.l    0(a3),a6
  180.     jmp    0(a0)
  181.  
  182. Finevnt    move.l    ExecB,a6
  183.     jmp    clfifo
  184.  
  185. Key    moveq    #0,d0
  186.     move.w    im_Code(a0),d0
  187.     btst.l    #7,d0
  188.     bne.s    Finevnt
  189.  
  190.     lea    Libstg,a3
  191.     move.l    0(a3),a6
  192.  
  193.     move.l    #0,d3
  194.     lea    KeyConv,a5
  195. Keylp    move.l    0(a5,d3.w),d1
  196.     cmpi.l    #$00FF,d1
  197.     beq.s    Finevnt        ; disable this to show keys
  198. ;    beq.s    gotoit        ; enable this to show keys
  199.     cmp.b    d0,d1
  200.     beq.s    gotoit
  201.     addi.l    #12,d3
  202.     jmp    Keylp
  203.  
  204. gotoit    move.l    8(a5,d3.w),d1
  205.     move.l    4(a5,d3.w),a5
  206.     jmp    0(a5)        ;disable this to show keys
  207.  
  208.                 ;enable the following to show keys
  209. ;    lea    VarPtr,a0
  210. ;    move.l    d0,4(a0)    ; Display the key on screen
  211. ;    jsr    Display
  212. ;    jmp    Finevnt
  213.  
  214. close    lea    Libstg,a3
  215.     move.l    0(a3),a6
  216.  
  217.     move.l    a4,a0
  218.     execute    CloseWindow
  219.  
  220. done    lea    Libstg,a3
  221.     move.l    0(a3),d0
  222.     beq.s    done2
  223.     move.l    d0,a1
  224.     move.l    ExecB,a6
  225.     execute    CloseLibrary
  226.  
  227. done2    lea    Libstg,a3
  228.     move.l    4(a3),d0
  229.     beq.s    done3
  230.     move.l    d0,a1
  231.     move.l    ExecB,a6
  232.     execute    CloseLibrary
  233.  
  234. done3    lea    BOT,a4    ; Memory de-allocation routine
  235.     moveq    #0,d1
  236. A_Err    subi.l    #16,d1
  237. daloc    move.l    0(a4,d1),d0
  238.     tst.l    d0
  239.     beq.s    fini
  240.     move.l    8(a4,d1),a1
  241.     movem.l    d1,-(a7)
  242.     execute FreeMem
  243.     movem.l    (a7)+,d1
  244.     subi.l    #16,d1
  245.     jmp    daloc(pc)
  246.  
  247. fini    moveq    #0,d0
  248.     rts
  249.  
  250. e_int    lea    dos,a1
  251.     moveq    #0,d0
  252.     execute    OpenLibrary
  253.     tst.l    d0
  254.     beq.s    e_dos
  255.     move.l    d0,a6
  256.     execute    Output
  257.     move.l    d0,d1
  258.     lea    Int_Err,a2
  259.     move.l    a2,d2
  260.     execute    Write
  261.     move.l    a6,a1
  262.     move.l    ExecB,a6
  263.     execute    CloseLibrary
  264.     moveq    #20,d0
  265. e_dos    jmp    done(pc)
  266.  
  267. ;********************************************************************
  268. ;            Amem                        *
  269. ;    INPUTS:    A6    =    Exec Library                *
  270. ;        D0    =    Number of Bytes                *
  271. ;        A2    =    Location of Source            *
  272. ;                                    *
  273. ;    OUTPUT:    D0    =    Pointer to Destination in CHIP MEM  *
  274. ;                                    *
  275. ;********************************************************************
  276.  
  277.  
  278. Amem    movem.l    a1/a4/d1,-(a7)
  279.     move.l    #MEMF_CHIP,d1        ; MEMF_CHIP
  280.     move.l    d0,d5
  281.     execute    AllocMem
  282.     tst.l    d0
  283.     beq.s    bad(pc)
  284.     move.l    d0,a3
  285.     moveq    #0,d0
  286. lp2    move.l    (a2)+,0(a3,d0)
  287.     addi.l    #4,d0
  288.     cmp.l    d5,d0
  289.     blt.s    lp2
  290.     move.l    a3,d0
  291.     movem.l    (a7)+,a1/a4/d1
  292. bad    rts
  293.  
  294.  
  295. ;*******************************************************
  296. ;*             Gadget Enables                          *
  297. ;*               2-F  (2-15)                           *
  298. ;*             a4 = window pointer                     *
  299. ;*             d4 = start                   *
  300. ;*           d5 = end                       *
  301. ;*******************************************************
  302.  
  303. GadEn    addi.l    #4,d5
  304.     move.l    #0,a2
  305.     lea    GadT,a3
  306. cir    move.l    0(a3,d4.w),a0
  307.     move.l    a4,a1
  308.     execute    OnGadget
  309.     addi.l    #4,d4
  310.     cmp.l    d5,d4
  311.     bne.s    cir
  312.     rts
  313.  
  314. ;*******************************************************
  315. ;*             Gadget Disables                         *
  316. ;*               2-F  (2-15)                           *
  317. ;*             a4 = window pointer                     *
  318. ;*             d4 = start                   *
  319. ;*           d5 = end                       *
  320. ;*******************************************************
  321.  
  322. GadDi    move.l    #0,a2
  323.     lea    GadT,a3
  324. cird    move.l    0(a3,d4.w),a0
  325.     move.l    a4,a1
  326.     execute    OffGadget
  327.     subi.l    #4,d4
  328.     cmp.l    d5,d4
  329.     bne.s    cird
  330.     rts
  331.  
  332. DHex    move.w    #0,d0        ; Hex Input Method
  333.     lea    Input,a0
  334.  
  335.     move.w    0(a0),d4
  336.     move.w    d0,0(a0)
  337.     cmpi.w    #0,d4
  338.     beq.l    Finevnt
  339.  
  340.     lea    InTbl,a0
  341.     move.l    0(a0),d5
  342.     mulu    #4,d4
  343.     move.l    0(a0,d4.w),d4
  344.  
  345.     jsr    GadEn
  346.  
  347.     lea    Tb,a0
  348.     move.b    #'H',0(a0)
  349.     move.b    #'e',1(a0)
  350.     move.b    #'x',2(a0)
  351.  
  352.     move.l    a4,a0
  353.     lea    Titl,a1
  354.     move.l    #-1,a2
  355.     execute    SetWindowTitles
  356.     jmp    Finevnt
  357.  
  358. DDec    move.w    #1,d0        ; Dec Input Method
  359.     lea    Input,a0
  360.  
  361.     move.w    0(a0),d4
  362.     move.w    d0,0(a0)
  363.     cmpi.w    #1,d4
  364.     beq.l    Finevnt
  365.     blt.s    didec
  366.  
  367.     lea    InTbl,a0
  368.     move.l    4(a0),d5
  369.     mulu    #4,d4
  370.     move.l    0(a0,d4.w),d4
  371.     jsr    GadEn
  372.     jmp    decf(pc)
  373.  
  374. didec    lea    InTbl,a0
  375.     move.l    4(a0),d5
  376.     mulu    #4,d4
  377.     move.l    0(a0,d4.w),d4
  378.     jsr    GadDi
  379.  
  380. decf    lea    Tb,a0
  381.     move.b    #'D',0(a0)
  382.     move.b    #'e',1(a0)
  383.     move.b    #'c',2(a0)
  384.  
  385.     move.l    a4,a0
  386.     lea    Titl,a1
  387.     move.l    #-1,a2
  388.     execute    SetWindowTitles
  389.     jmp    Finevnt
  390.  
  391. DOct    move.w    #2,d0        ; Oct Input Method
  392.     lea    Input,a0
  393.  
  394.     move.w    0(a0),d4
  395.     move.w    d0,0(a0)
  396.     cmpi.w    #2,d4
  397.     beq.l    Finevnt
  398.     blt.s    dioct
  399.  
  400.     lea    InTbl,a0
  401.     move.l    8(a0),d5
  402.     mulu    #4,d4
  403.     move.l    0(a0,d4.w),d4
  404.     jsr    GadEn
  405.     jmp    octf(pc)
  406.  
  407. dioct    lea    InTbl,a0
  408.     move.l    8(a0),d5
  409.     mulu    #4,d4
  410.     move.l    0(a0,d4.w),d4
  411.     jsr    GadDi
  412.  
  413. octf    lea    Tb,a0
  414.     move.b    #'O',0(a0)
  415.     move.b    #'c',1(a0)
  416.     move.b    #'t',2(a0)
  417.  
  418.     move.l    a4,a0
  419.     lea    Titl,a1
  420.     move.l    #-1,a2
  421.     execute    SetWindowTitles
  422.     jmp    Finevnt
  423.  
  424. DBin    move.w    #3,d0        ; Bin Input Method
  425.     lea    Input,a0
  426.  
  427.     move.w    0(a0),d4
  428.     move.w    d0,0(a0)
  429.     cmpi.w    #3,d4
  430.     beq.l    Finevnt
  431.  
  432.     lea    InTbl,a0
  433.     move.l    12(a0),d5
  434.     mulu    #4,d4
  435.     move.l    0(a0,d4.w),d4
  436.     jsr    GadDi
  437.  
  438. binf    lea    Tb,a0
  439.     move.b    #'B',0(a0)
  440.     move.b    #'i',1(a0)
  441.     move.b    #'n',2(a0)
  442.  
  443.     move.l    a4,a0
  444.     lea    Titl,a1
  445.     move.l    #-1,a2
  446.     execute    SetWindowTitles
  447.     jmp    Finevnt
  448.  
  449.  
  450. TitlR    move.l    a4,a0
  451.     lea    ReqNam,a1
  452.     move.l    #-1,a2
  453.     execute    SetWindowTitles
  454.     move.l    a4,a0
  455.     lea    Itext0,a1
  456.     move.l    #0,a2
  457.     lea    Iok,a3
  458.     moveq    #0,d0
  459.     move.l    #0,d1
  460.     move.l    #350,d2
  461.     move.l    #125,d3
  462.     execute    AutoRequest
  463.     move.l    a4,a0
  464.     lea    Titl,a1
  465.     move.l    #-1,a2
  466.     execute    SetWindowTitles
  467.     jmp    Finevnt
  468.  
  469. TitlH    move.l    a4,a0
  470.     lea    ReqNam1,a1
  471.     move.l    #-1,a2
  472.     execute    SetWindowTitles
  473.     move.l    a4,a0
  474.     lea    HItext0,a1
  475.     move.l    #0,a2
  476.     lea    Igt,a3
  477.     moveq    #0,d0
  478.     move.l    #0,d1
  479.     move.l    #440,d2
  480.     move.l    #145,d3
  481.     execute    AutoRequest
  482.     move.l    a4,a0
  483.     lea    Titl,a1
  484.     move.l    #-1,a2
  485.     execute    SetWindowTitles
  486.     jmp    Finevnt
  487.  
  488.  
  489.  
  490. ;    Memory allocation Table for all chip destined data
  491. ;        Bytes,Source,Destination(CHIP),Install Address
  492.  
  493.     dc.l    0,0,0,0         ; so we can find the top
  494. Table    dc.l    204,HEX,0,hp
  495.     dc.l    204,Octal,0,ocp
  496.     dc.l    204,Decimal,0,dp
  497.     dc.l    204,BIN,0,Bp
  498.     dc.l    204,_CLR,0,Cp
  499.     dc.l    144,Zero,0,zp
  500.     dc.l    144,One,0,op
  501.     dc.l    144,Two,0,twop
  502.     dc.l    144,Three,0,thrp
  503.     dc.l    144,Four,0,fp
  504.     dc.l    144,Five,0,fip
  505.     dc.l    144,Six,0,sip
  506.     dc.l    144,Seven,0,sep
  507.     dc.l    144,Eight,0,ep
  508.     dc.l    144,Nine,0,np
  509.     dc.l    144,Ten,0,tp
  510.     dc.l    144,Eleven,0,elp
  511.     dc.l    144,Twelve,0,twp
  512.     dc.l    144,Thrten,0,thp
  513.     dc.l    144,Forten,0,fop
  514.     dc.l    144,Fiften,0,fifp
  515.     dc.l    144,Plus,0,Plp
  516.     dc.l    144,Minus,0,Mip
  517.     dc.l    144,Multi,0,Mup
  518.     dc.l    144,Divide,0,Dip
  519.     dc.l    144,Equal,0,Eqp
  520.     dc.l    1260,_Title,0,Tip
  521. BOT    dc.l    0,0,0,0          ; bottom
  522.  
  523.  
  524. KeyConv    dc.l    $17,TitlR,0    ;I
  525.     dc.l    $5F,TitlH,0    ;HELP
  526.     dc.l    $45,close,0    ;ESC
  527.  
  528.     dc.l    $A,num,0    ;0
  529.     dc.l    1,num,1        ;1
  530.     dc.l    2,num,2        ;2
  531.     dc.l    3,num,3        ;3
  532.     dc.l    4,num,4        ;4
  533.     dc.l    5,num,5        ;5
  534.     dc.l    6,num,6        ;6
  535.     dc.l    7,num,7        ;7
  536.     dc.l    8,num,8        ;8
  537.     dc.l    9,num,9        ;9
  538.  
  539.     dc.l    $F,num,0    ;0
  540.     dc.l    $1D,num,1    ;1
  541.     dc.l    $1E,num,2    ;2
  542.     dc.l    $1F,num,3    ;3
  543.     dc.l    $2D,num,4    ;4
  544.     dc.l    $2E,num,5    ;5
  545.     dc.l    $2F,num,6    ;6
  546.     dc.l    $3D,num,7    ;7
  547.     dc.l    $3E,num,8    ;8
  548.     dc.l    $3F,num,9    ;9
  549.  
  550.     dc.l    $20,num,$A    ;A
  551.     dc.l    $35,num,$B    ;B
  552.     dc.l    $33,num,$C    ;C
  553.     dc.l    $22,num,$D    ;D
  554.     dc.l    $12,num,$E    ;E
  555.     dc.l    $23,num,$F    ;F
  556.  
  557.     dc.l    $50,num,$A    ;F1
  558.     dc.l    $51,num,$B    ;F2
  559.     dc.l    $52,num,$C    ;F3
  560.     dc.l    $53,num,$D    ;F4
  561.     dc.l    $54,num,$E    ;F5
  562.     dc.l    $55,num,$F    ;F6
  563.  
  564.     dc.l    $56,DHex,$0    ;F7
  565.     dc.l    $57,DOct,$0    ;F8
  566.     dc.l    $58,DBin,$0    ;F9
  567.     dc.l    $59,DDec,$0    ;F10
  568.  
  569.     dc.l    $46,Clear,26    ;DEL
  570.  
  571.     dc.l    $0C,Funct,16    ;+
  572.     dc.l    $0B,Funct,17    ;-
  573.     dc.l    $4A,Funct,17    ;-
  574.     dc.l    $32,Funct,18    ;*
  575.     dc.l    $3A,Funct,19    ;/
  576.  
  577.     dc.l    $44,Funct,20    ;=
  578.     dc.l    $43,Funct,20    ;=
  579.  
  580.     dc.l    94,Funct,16    ;+ for Amy 500&2000
  581.     dc.l    93,Funct,18    ;* for Amy 500&2000
  582.     dc.l    92,Funct,19    ;/ for Amy 500&2000
  583.  
  584.     dc.l    $FF,0        ;End of KeyConv table
  585.     dc.l    $FF,0        ;End of KeyConv table
  586.     dc.l    $FF,0        ;End of KeyConv table
  587.     dc.l    $FF,0        ;End of KeyConv table
  588.  
  589. jptbl    dc.l    num
  590.     dc.l    num
  591.     dc.l    num
  592.     dc.l    num
  593.     dc.l    num
  594.     dc.l    num
  595.     dc.l    num
  596.     dc.l    num
  597.     dc.l    num
  598.     dc.l    num
  599.     dc.l    num
  600.     dc.l    num
  601.     dc.l    num
  602.     dc.l    num
  603.     dc.l    num
  604.     dc.l    num
  605.     dc.l    Funct
  606.     dc.l    Funct
  607.     dc.l    Funct
  608.     dc.l    Funct
  609.     dc.l    Funct
  610.     dc.l    TitlR
  611. ;22 is Hex
  612.     dc.l    DHex
  613.     dc.l    DOct
  614. ;24 is Dec
  615.     dc.l    DDec
  616.     dc.l    DBin
  617.     dc.l    Clear
  618.  
  619.     dc.l    Finevnt
  620.     dc.l    Finevnt
  621.     dc.l    Finevnt
  622.  
  623. MyWin    dc.w    10,10,409,119
  624.     dc.b    0,1
  625.     dc.l    CLOSEWINDOW+GADGETUP+RAWKEY
  626.     dc.l    ACTIVATE+WINDOWDEPTH+WINDOWCLOSE+WINDOWDRAG
  627.     dc.l    Gadg,0
  628.     dc.l    Titl
  629.     dc.l    0,0
  630.     dc.w    20,20,350,100
  631.     dc.w    WBENCHSCREEN
  632.  
  633. Titl    dc.b    'Compu-Calc  Ver 1.00        Input:'
  634. Tb    dc.b    'Hex',0
  635.  
  636. Libstg    ds.l    2        ; long 0=Intuit 1=graphics
  637.  
  638. Input    ds.w    1        ; 0=Hex 1=Dec 2=Oct 3=Bin
  639. InTbl    dc.l    60,36,28,4
  640.  
  641. Int_Err    dc.b    'Error Opening A Library',0
  642. intuit    dc.b    'intuition.library',0
  643. dos    dc.b    'dos.library',0
  644. graph    dc.b    'graphics.library',0
  645.  
  646.  
  647.     END
  648.